"""
通知组件
"""
import streamlit as st
from datetime import datetime


def show_toast(message: str, type: str = "info", duration: int = 3):
    """
    显示临时通知
    
    Args:
        message: 通知内容
        type: 通知类型 (info/success/warning/error)
        duration: 显示时长(秒)
    """
    if type == "info":
        st.toast(message, icon="ℹ️")
    elif type == "success":
        st.toast(message, icon="✅")
    elif type == "warning":
        st.toast(message, icon="⚠️")
    elif type == "error":
        st.toast(message, icon="❌")
    else:
        st.toast(message)


def show_alert(message: str, type: str = "info"):
    """
    显示持久化警告
    """
    if type == "info":
        st.info(message)
    elif type == "success":
        st.success(message)
    elif type == "warning":
        st.warning(message)
    elif type == "error":
        st.error(message)
    else:
        st.write(message)


def log_operation(operation: str, details: str = ""):
    """
    记录操作日志
    """
    if "operation_logs" not in st.session_state:
        st.session_state.operation_logs = []
    
    log_entry = {
        "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        "operation": operation,
        "details": details
    }
    
    st.session_state.operation_logs.append(log_entry)